<?php
include_once '../utils/WCRelation.php';
include_once '../utils/WCDBLayer.php';
include_once '../conf/Conf.php';

//I am going to assume this is going to work...
$db = new WCDBLayer(Conf::$db_url,Conf::$db_user,Conf::$db_password);
$db->connect(Conf::$db);

$rel = new WCRelation($db);
$rel->setAttribute('child_id',1);
$rel->setAttribute('parent_id',2);

$rel->setAttribute('child_type','cool');
$rel->setAttribute('parent_type','cooler');
try{
	$rel->save();
}catch(WCException $e){	
	echo '<p class="error">Error ',$e->getCode()+': ',$e->getMessage(),' encountered while attempting to create table wc_relation.</p>';
	echo $e->printHTMLTrace();
}

$id = $rel->getId();
unset($rel);

$rel = new WCRelation($db,$id);
$rel->dump();
$rel->setAttribute('parent_id',1000);
$rel->save();

unset($rel);

$rel = new WCRelation($db,$id);
$rel->dump();

echo 'child_id set: '.$rel->isAttrSet('child_id');
echo 'does_not_exist set: '.$rel->isAttrSet('does_not_exist');

$rel->setAttribute('does_not_exist','if inserted go boom!!');

$rel->setAttribute('relation_type',"I'm ga-ga about (parenthesis) #signs and \\ slashes!!");
$rel->save();

unset($rel);

$rel = new WCRelation($db,$id);
$rel->dump();

$rel->delete();
?>
